package cn.qyd.javasynchronized;

import java.util.ArrayList;

/**
 * @author 邱运铎
 * @date 2024-03-14 22:12
 */
public class SynchronizedDemo02 implements Runnable{
    static int i;

    public synchronized static void incrementI() {
        i++;
    }

    public synchronized void incrementI01() {
        i++;
    }
    @Override
    public void run() {
        for (int j = 0; j < 10000; j++) {
            incrementI01();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new SynchronizedDemo02());
        Thread thread2 = new Thread(() -> {
            for (int j = 0; j < 10000; j++) {
                incrementI();
            }
        });

        thread1.start();
        thread2.start();

        thread1.join();
        thread2.join();

        System.out.println("i result is : " + i);
    }
}

